<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #tableTitle>
        <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd">新增</a-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="ant-design:delete-outlined"></Icon>
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button>批量操作
            <Icon style="fontSize:12px" icon="ant-design:down-outlined"></Icon>
          </a-button>
        </a-dropdown>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getActions(record)" />
      </template>
    </BasicTable>
    <StoreTagDrawer @register="registerDrawer" @success="reload" />
  </div>
</template>
<script lang="ts" name="shop-store-tag" setup>
import { ref, onMounted, unref } from 'vue';
import { Icon } from '/@/components/Icon';
import { BasicTable, TableAction } from '/@/components/Table';
import { useDrawer } from '/@/components/Drawer';
import StoreTagDrawer from './StoreTagDrawer.vue';
import { useMethods } from '/@/hooks/system/useMethods';
import { useGlobSetting } from '/@/hooks/setting';
import { columns, searchFormSchema } from './storeTag.data';
import { listStoreTag, deleteStoreTag, batchDeleteStoreTag } from './storeTag.api';
import { useListPage } from '/@/hooks/system/useListPage';

const tenantId = ref(null)
const glob = useGlobSetting();
const [registerDrawer, { openDrawer }] = useDrawer();
// 列表页面公共参数、方法
const { prefixCls, tableContext } = useListPage({
  designScope: 'article-group',
  tableProps: {
    title: '门店标签',
    api: listStoreTag,
    bordered: false,
    columns: columns,
    formConfig: {
      schemas: searchFormSchema,
      showResetButton: false
    },
  }
})

const [registerTable, { reload, getForm }, { rowSelection, selectedRowKeys }] = tableContext

onMounted(() => {
  const { updateSchema } = getForm()

})


/**
 * 新增事件
 */
function handleAdd() {
  openDrawer(true, {
    isUpdate: false
  });
}

/**
 * 编辑事件
 */
function handleEdit(record) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}

/**
 * 删除事件
 */
async function handleDelete(record) {
  await deleteStoreTag({ id: record.id }, reload);
}

/**
 * 批量删除事件
 */
async function batchHandleDelete() {
  await batchDeleteStoreTag({ ids: selectedRowKeys.value }, reload);
}

/**
 * 操作列定义
 * @param record
 */
function getActions(record) {
  return [
    {
      label: '编辑',
      onClick: handleEdit.bind(null, record),
      // ifShow: record.sendStatus == 0
    },
    {
      label: '删除',
      ifShow: record.sendStatus != 1,
      popConfirm: {
        title: '是否确认删除',
        confirm: handleDelete.bind(null, record),
      },
    },
  ]
}

</script>
